import java.util.Random;
import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args) {
        int num = (int) (Math.random()*100+1);
        //打印输出
        System.out.println("获得的随机数为："+ num);

        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()){
            String s = scan.nextLine();
            String[] str=s.split(",");
            int[] a= new int[str.length];
            for(int i =0;i<str.length;i++){
                a[i] = Integer.parseInt(str[i]);
                System.out.println("玩家输入的数为："+a[i]);

                //比较
                int chances = 7;
                while (chances > 0) {
                    System.out.println("请输入一个1-100之间的整数，含1和100，你还有" + chances + "次机会：");
                    int guess = scan.nextInt();
                    //4.比较一次并给出反馈
                    if (guess >num) {
                        System.out.println("大了");
                    } else if (guess < num) {
                        System.out.println("小了");
                    } else {
                        System.out.println("恭喜你！猜对啦！");
                        break;
                    }
                    chances--;
                }
                System.out.println("再玩一次吗?(y/n)");
                String again = scan.next();
                if (!again.equalsIgnoreCase("y")) {
                    break;
                }
            }
        }
    }
}
